<template>
  <el-form :model="form" ref="formRef" label-width="80px">
    <el-form-item label="预约时间" prop="date" :rules="[{ required: true, message: '请选择时间' }]">
      <el-date-picker v-model="form.date" type="datetime" placeholder="选择时间"/>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="form.remark"/>
    </el-form-item>
    <el-button type="primary" @click="submitOrder">预约</el-button>
  </el-form>
</template>

<script setup>
import { ref } from 'vue'
import { createOrder } from '@/api/order'
import { ElMessage } from 'element-plus'
const props = defineProps(['serviceId'])
const emit = defineEmits(['order-success'])
const form = ref({ date: '', remark: '' })
const formRef = ref(null)

async function submitOrder() {
  formRef.value.validate(async (valid) => {
    if (!valid) return
    try {
      const res = await createOrder({
        serviceId: props.serviceId,
        date: form.value.date,
        remark: form.value.remark
      })
      ElMessage.success('预约成功')
      emit('order-success', res.data.orderId || res.data.id)
    } catch {
      ElMessage.error('预约失败')
    }
  })
}
</script> 